/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.discount.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.discount.entity.DiscountMall;
import com.jeesite.modules.discount.service.DiscountMallService;

/**
 * 商场管理Controller
 * @author czp
 * @version 2018-07-08
 */
@Controller
@RequestMapping(value = "${adminPath}/discount/discountMall")
public class DiscountMallController extends BaseController {

	@Autowired
	private DiscountMallService discountMallService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DiscountMall get(String id, boolean isNewRecord) {
		return discountMallService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("discount:discountMall:view")
	@RequestMapping(value = {"list", ""})
	public String list(DiscountMall discountMall, Model model) {
		model.addAttribute("discountMall", discountMall);
		return "modules/discount/discountMallList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("discount:discountMall:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DiscountMall> listData(DiscountMall discountMall, HttpServletRequest request, HttpServletResponse response) {
		Page<DiscountMall> page = discountMallService.findPage(new Page<DiscountMall>(request, response), discountMall); 
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("discount:discountMall:view")
	@RequestMapping(value = "form")
	public String form(DiscountMall discountMall, Model model) {
		model.addAttribute("discountMall", discountMall);
		return "modules/discount/discountMallForm";
	}

	/**
	 * 保存商场管理
	 */
	@RequiresPermissions("discount:discountMall:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DiscountMall discountMall) {
		discountMallService.save(discountMall);
		return renderResult(Global.TRUE, "保存商场管理成功！");
	}
	
	/**
	 * 停用商场管理
	 */
	@RequiresPermissions("discount:discountMall:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DiscountMall discountMall) {
		discountMall.setStatus(DiscountMall.STATUS_DISABLE);
		discountMallService.updateStatus(discountMall);
		return renderResult(Global.TRUE, "停用商场管理成功");
	}
	
	/**
	 * 启用商场管理
	 */
	@RequiresPermissions("discount:discountMall:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DiscountMall discountMall) {
		discountMall.setStatus(DiscountMall.STATUS_NORMAL);
		discountMallService.updateStatus(discountMall);
		return renderResult(Global.TRUE, "启用商场管理成功");
	}
	
	/**
	 * 删除商场管理
	 */
	@RequiresPermissions("discount:discountMall:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DiscountMall discountMall) {
		discountMallService.delete(discountMall);
		return renderResult(Global.TRUE, "删除商场管理成功！");
	}
	
}